package com.dx.as.common;

import android.content.Context;
import android.os.Environment;

import com.dx.as.JWCache;
import com.dx.as.common.bean.DeviceInfo;
import com.dx.as.common.storage.StorageType;
import com.dx.as.common.string.StringUtil;
import com.dx.as.config.Config;
import com.dx.as.config.preference.Preferences;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jwaoo on 2017/5/25.
 */

public class CommonUtils {
    private static DeviceInfo deviceInfo;
    private static Map<Integer,TypeToken> typeTokenMap = new HashMap<>();
    public static void addTypeToken(Integer hasCode, TypeToken typeToken){
        typeTokenMap.put(hasCode, typeToken);
    }
    private Map<Integer,TypeToken> getTypeTokenMap(){
        return typeTokenMap;
    }
    public static void removeTypeToken(Integer hasCode){
        typeTokenMap.remove(hasCode);
    }
    public static Type getType(Integer hasCode){
        return typeTokenMap.get(hasCode).getType();
    }
    public static String getDBName(){
        return Config.DB_NAME;
    }
    public static DeviceInfo getDeviceInfo(){
        return deviceInfo;
    }
    public static void setDeviceInfo(DeviceInfo deviceInfo){
        CommonUtils.deviceInfo = deviceInfo;
    }
    public static String getBaseDir(Context context){
        String externalPath = context.getExternalFilesDir(null).getAbsolutePath();
        return externalPath +"/";
    }

    public static String getLogDir(Context context){
        return getBaseDir(context)+ StorageType.TYPE_LOG.getStoragePath();
    }

    public static String getImgDir(Context context){
        return getBaseDir(context)+StorageType.TYPE_IMAGE.getStoragePath();
    }

    public static String getAudioDir(Context context){
        return getBaseDir(context)+StorageType.TYPE_AUDIO.getStoragePath();
    }

    public static String getVideoDir(Context context){
        return getBaseDir(context)+StorageType.TYPE_VIDEO.getStoragePath();
    }

    public static boolean isLogin(){
        if (StringUtil.isEmpty(getToken())) return false;
        return true;
    }

    public static void saveAccount(String account) {
        Preferences.saveUserAccount(account);
    }

    public static String getAccount(){
        return Preferences.getUserAccount();
    }

    public static void saveIMName(String showName){
        Preferences.saveIMName(showName);
    }

    public static String getIMName(){
        return Preferences.getIMName();
    }

    public static void saveIMAccount(int imAccount){
        Preferences.saveIMAccount(imAccount);
    }

    public static int getIMAccount(){
        return Preferences.getIMAccount();
    }

    public static void saveToken(String token){
        Preferences.saveUserToken(token);
    }
    public static void savePerfect(int perfect){
        Preferences.savePerfect(perfect);
    }

    public static int getPerfect(){
        return Preferences.getPerfect();
    }


    public static String getToken(){
        return Preferences.getUserToken();
    }
}
